//2．编写一个函数，提示用户输入日、月和年。月份可以是月份号、月份名或月份名缩写。
//然后该程序应返回一年中到用户指定日子（包括这一天）的总天数。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

struct month {
    char name[10];
    char abbr[4];
    int days;
    int monumb;
};

int main() {
    struct month months[12] = {
            {"January",   "jan", 31, 1},
            {"February",  "feb", 28, 2},
            {"March",     "mar", 31, 3},
            {"April",     "apr", 30, 4},
            {"May",       "may", 31, 5},
            {"June",      "jun", 30, 6},
            {"July",      "jul", 31, 7},
            {"August",    "aug", 31, 8},
            {"September", "sep", 30, 9},
            {"October",   "oct", 31, 10},
            {"November",  "nov", 30, 11},
            {"December",  "dec", 31, 12}
    };
    int monthNumber;
    char mon[81];
    int day;
    int year;
    int test;
    printf("please Enter day month year:");
    test = scanf("%d", &day);
    if (test == 0 || day > 31 || day < 1) {
        puts("日期应在1-31之间\n");
        exit(EXIT_FAILURE);
    }
    test = scanf("%s", mon);
    if (test == 0) {
        puts("未输入月份可以输入月份名，月份编号或月份简写");
        exit(EXIT_FAILURE);
    }
    bool comp_result = false;
    for (int i = 0; i < 12; ++i) {
        char str[3];
        sprintf(str, "%d", months[i].monumb);
        bool b1 = strcmp(mon, months[i].name) == 0;
        bool b2 = strcmp(mon, months[i].abbr) == 0;
        bool b3 = strcmp(mon, str) == 0;
        comp_result = b1 || b2 || b3;
        if (comp_result) {
            monthNumber = months[i].monumb;
            if (day > months[i].days) {
                printf("本月最大日期是%d,你的输入是%d\n", months[i].days, day);
                exit(EXIT_FAILURE);
            }
            break;
        }
    }
    if (!comp_result) {
        puts("检查输入的月份，可以输入月份名，月份编号或月份简写");
        exit(EXIT_FAILURE);
    }
    test = scanf("%d", &year);
    if (test == 0 || year < 1950 || year > 2050) {
        puts("输入1970-2050的年份");
        exit(EXIT_FAILURE);
    }


    int sumDay = 0;
    for (int i = 0; i < 12; ++i) {
        if (months[i].monumb < monthNumber) {
            sumDay += months[i].days;
        } else if (months[i].monumb == monthNumber) {
            sumDay += day;
        }
    }
    printf("%d-jan-1 to %d-%d-%d have %d days\n", year, year, monthNumber, day, sumDay);
}